package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameBuff extends JFrame
	{
		public function FrameBuff()
		{
			setClosable(false);
			setResizable(false);  
			setDragable(false);
			setBorder(new EmptyBorder());
			this.setTitleBar(null);
			this.setBackgroundDecorator(null);
			
			//component creation
			setSize(new IntDimension(251, 20));
			setPreferredSize(new IntDimension(251, 20));
			var layout0:FlowWrapLayout = new FlowWrapLayout();
			layout0.setPreferWidth(200);
			layout0.setAlignment(AsWingConstants.LEFT);
			layout0.setHgap(1);
			layout0.setVgap(1);
			layout0.setMargin(false);
			getContentPane().setLayout(layout0);
			
			this.setClipMasked(false);
			getContentPane().setClipMasked(false);
			setImages()
		}
		private var _items:Array = new Array();
		
		public function setImages():void
		{
			setLocationXY(4,97);
			for(var i:int = 0; i < 12; i++)
			{
				var item:PaneBuffItem = new PaneBuffItem;
				getContentPane().append(item);
				_items.push(item);
			}
		}
		public function update():void
		{
			for each(var obj:Object in _items)
			{
				obj.item = null;
			}
			
			var nIndex:int = 0;
			var array:Array = CharInfo.m_arBuffs;
			for each(var item:Object in array)
			{
				_items[nIndex++].item = item;
				if(nIndex >= 12)
					break;
			}
		}
		
		public static var _timeBuffUpdate:Timer = null;
		
		public static function phBuffs_1700(e:PacketEvent):void
		{
			var msg:Array = e.data as Array;
			trace("phBuffs_1700", msg);
			var nIndex:uint = 0;
			var nCount:uint = msg[nIndex++];
			var array:Array = CharInfo.m_arBuffs;
			array.splice(0,array.length);
			for(var i:int = 0; i < nCount; i++)
			{
				var obj:Object = new Object();
				array[i] = obj;
				obj.index = i;
				obj.csv_id = msg[nIndex++];
				obj.m_tElapsedTime = msg[nIndex++];
				obj.m_tRetentionTime = msg[nIndex++];
			}
			if(_frame != null)
			{
				_frame.update();
			}
			if(_timeBuffUpdate == null)
			{
				_timeBuffUpdate = new Timer(1000);
				_timeBuffUpdate.addEventListener(TimerEvent.TIMER,onTimerUpdateBuffInfo);
			}
			if(!_timeBuffUpdate.running)
				_timeBuffUpdate.start();
		}
		
		public static function onTimerUpdateBuffInfo(e:TimerEvent):void
		{
			if(CharInfo.m_arBuffs.length == 0)
			{
				_timeBuffUpdate.stop();
				return;
			}
			var needUpdate:Boolean = false;
			for each(var obj:Object in CharInfo.m_arBuffs)
			{
				obj.m_tElapsedTime++;
				if(obj.m_tElapsedTime >= obj.m_tRetentionTime)
					needUpdate = true;
			}
			if(needUpdate)
				Client.getInstance().sendPacketLogic(1701,[int(0)]);
			
			if(_frame == null)
				return;
			var nIndex:int = 0;
			var array:Array = CharInfo.m_arBuffs;
			for each(var item:Object in array)
			{
				_frame._items[nIndex++].update();
				if(nIndex >= 12)
					break;
			}
		}
		
		public static var _frame:FrameBuff = null;
		public static function show():void
		{
			if(_frame == null)
			{
				_frame = new FrameBuff();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			_frame.update();
			PanelMainHelp.getInstance().bringToTop(_frame);
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}

import com.*;
import com.Engine.*;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;

/**
 * MyPaneBuffItem
 */
class PaneBuffItem extends JPanel{
	
	//members define
	private var _tooltip:ToolTipBuff = new ToolTipBuff();
	/**
	 * MyPaneBuffItem Constructor
	 */
	public var panelImage:JPanel;
	public var labelCount:JLabel;
	public function PaneBuffItem(){
		//component creation
		setSize(new IntDimension(20, 20));
		setPreferredSize(new IntDimension(20, 20));
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		panelImage = new JPanel();
		panelImage.setLocation(new IntPoint(1, 1));
		panelImage.setSize(new IntDimension(18, 18));
		panelImage.setPreferredSize(new IntDimension(18, 18));
		
		labelCount = new JLabel();
		labelCount.setLocation(new IntPoint(1, 7));
		labelCount.setSize(new IntDimension(19, 13));
		
		//component layoution
		append(panelImage);
		append(labelCount);
		
		//component layoution
		addEventListener(MouseEvent.ROLL_OVER, onRollOver);
		addEventListener(MouseEvent.ROLL_OUT, onRollOut);
		setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_skill_bg") as DisplayObject));
		this.setClipMasked(false);
		//labelCount.setForeground(ASColor.RED);
		
		var filter:GlowFilter;
		var font:ASFont = new ASFont("宋体", 12, false, false, false, false);
		filter = new GlowFilter(0x000000, 1, 2, 2, 10);
		labelCount.setFont(font);
		labelCount.setForeground(ASColor.RED);
		labelCount.setTextFilters(new Array(filter));
	}
	
	private var filterArray:Array = new Array(new GlowFilter(0xFFFF00, 1, 2, 2, 3));
	private var filterArrayImage:Array = new Array(new GlowFilter(0xEA0000, 0.6, 34, 34, 2,1,true));
	private function onRollOver(event:MouseEvent):void
	{
		
		if(filters != filterArray)
			filters = filterArray;
		
		if(this.parent is Container)
			(this.parent as Container).bringToTop(this);
	}
	
	private function onRollOut(event:MouseEvent):void
	{
		filters = null;
	}
	
	private var _item:Object = null;
	public function set item(val:Object):void
	{
		//panelImage.setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_default_image") as DisplayObject));
		_item = val;
		_tooltip.setTargetComponent(null);
		panelImage.setBackgroundDecorator(null);
		labelCount.setText("");
		//panelImage.setBackgroundDecorator(null);
		if(_item == null)
		{
			setBackgroundDecorator(null);
			return;
		}
		
		var objBuffCSV:Object = Client.getInstance().GetBuffCSV(_item.csv_id);
		if(objBuffCSV == null)
		{
			setBackgroundDecorator(null);
			return;
		}
		
		_tooltip.setItem(_item);
		_tooltip.setTargetComponent(this);
		
		setBackgroundDecorator(new AssetBackground(Client.getUIElement("img_skill_bg") as DisplayObject));
		panelImage.setBackgroundDecorator(new AssetBackground(Client.getBuffElement("img_buff_"+ objBuffCSV.icon_id) as DisplayObject));

		update();
		panelImage.pack();
		panelImage.paintImmediately();
		pack();
		this.paintImmediately();
		
	}
	
	public function clear():void
	{
		setBackgroundDecorator(null);
	}
	
	public function update():void
	{
		if(_item.m_tRetentionTime - _item.m_tElapsedTime <= 60)
		{
			//labelCount.setText(formatTime(int(_item.m_tRetentionTime - _item.m_tElapsedTime)));
			labelCount.setText((int(_item.m_tRetentionTime - _item.m_tElapsedTime)).toString());
			panelImage.filters = filterArrayImage;
		}
		else
		{
			panelImage.filters = null;
			labelCount.setText("");
		}
		_tooltip.update();
	}
	
	static public function formatTime(time:int):String
	{
		var str:String = new String;
		var hour:int = time / 3600;
		var min:int = (time % 3600)/60;
		var second:int = time%60;
		if(hour > 0)str += ((hour < 10) ? "0" : "") + hour+':';
		if(min >= 0)str += ((min < 10) ? "0" : "") + min+':';
		str += ((second < 10) ? "0" : "") + second;
		return str;
	}
	//_________getters_________
	
	
}

class ToolTipBuff extends JToolTip
{
	protected var panelToolTipSkill:PanelToolTipBuff;
	
	public function ToolTipBuff()
	{
		this.setBackground(new ASColor(0,0));
		this.setForeground(new ASColor(0,0));
		this.setBackgroundDecorator(null);
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		panelToolTipSkill = new PanelToolTipBuff();
		panelToolTipSkill.setLocation(new IntPoint(0, 0));
		panelToolTipSkill.setSize(new IntDimension(200, 200));
		
		append(panelToolTipSkill);
		this.setClipMasked(false);
	}
	/*public static var _timeBuffUpdate:Timer = null;
	private function onShown(e:Event):void
	{
		textField.setHtmlText(_baseDesc + '\n<font color="#FFFF00">剩余时间:'+PaneBuffItem.formatTime(int(_item.m_tRetentionTime - _item.m_tElapsedTime))+'</font>');
		
		if(_timeBuffUpdate == null)
		{
			_timeBuffUpdate = new Timer(1000);
			_timeBuffUpdate.addEventListener(TimerEvent.TIMER,onTimerUpdateBuffInfo);
		}
		if(!_timeBuffUpdate.running)
			_timeBuffUpdate.start();
	}
	public function onTimerUpdateBuffInfo(e:TimerEvent):void
	{
		textField.setHtmlText(_baseDesc + '\n<font color="#FFFF00">剩余时间:'+PaneBuffItem.formatTime(int(_item.m_tRetentionTime - _item.m_tElapsedTime))+'</font>');
	}*/
	public function update():void
	{
		panelToolTipSkill.update();
	}
	private var _item:Object;
	private var icon_id:int = 0;
	public function setItem(item:Object):void 
	{
		setTipText("");
		var width:int = 200;
		var height:int = 100;
		panelToolTipSkill.setItem(item);
		height = panelToolTipSkill.height;
		this.setPreferredWidth(200);
		setSize(new IntDimension(width, height));
		this.pack();
		this.paintImmediately();
		return;
	}
	public function clear():void
	{
		setBackgroundDecorator(null);
	}
}

import com.*;
import com.UI.*;
import com.Engine.*;
import com.Packet.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
/**
 * ToolTipItem
 */
class PanelToolTipBuff extends PanelToolTipItem{
	
	
	/**
	 * ToolTipItem Constructor
	 */
	public function PanelToolTipBuff(){
	}
	
	public function update():void
	{
		textField.setHtmlText(_baseDesc + '\n<font color="#FFFF00">剩余时间:'+PaneBuffItem.formatTime(int(_item.m_tRetentionTime - _item.m_tElapsedTime))+'</font>');
	}
	private var icon_id:int = 0;
	private var _item:Object = null;
	private var _baseDesc:String = "";
	override public function setItem(item:Object):void 
	{
		_item = item;
		//setTipText("");
		if(item == null)
		{
			icon_id = 0;
			panelIcon.setBackgroundDecorator(null);
			return;
		}
		
		var objBuffCSV:Object = Client.getInstance().GetBuffCSV(item.csv_id);
		if(objBuffCSV == null)
		{
			icon_id = 0;
			panelIcon.setBackgroundDecorator(null);
			return;
		}
		
		if(icon_id != objBuffCSV.icon_id)
		{
			icon_id = objBuffCSV.icon_id;
			panelIcon.setBackgroundDecorator(new AssetBackground(Client.getBuffElement("img_buff_"+icon_id) as DisplayObject));
		}
		
		labelName.setText(objBuffCSV.name);
		
		
		_baseDesc = "";
		//text += objItemCSV.name+"\n"
		if(objBuffCSV.description.length != 0)
			_baseDesc += objBuffCSV.description +"\n";
		//'<font color="#FFFF00">物品:</font>' +
		//text += '<font color="#FFFF00">暂用测试地址:</font><a href="http://119.145.144.150"><u><font color="#0000FF">点此处进入</font></u></a>';
		//text += '<font color="#FFFF00">'+_objTaskInfo.task_name+'</font>';
		//_baseDesc += '<br><font color="#FFFF00">剩余时间:'+PaneBuffItem.formatTime(int(_item.m_tRetentionTime - _item.m_tElapsedTime))+'</font>';
		//textField.setHtmlText(_baseDesc);
		//textField.setHtmlText(_baseDesc + '\n<font color="#FFFF00">剩余时间:'+PaneBuffItem.formatTime(int(_item.m_tRetentionTime - _item.m_tElapsedTime))+'</font>');
		update();
		
		textField.pack();
		textField.paintImmediately();
		panelBottom.pack();
		panelBottom.paintImmediately();
		var square:Sprite = new Sprite();
		
		square.graphics.beginFill(0x033332, 0.9);
		square.graphics.drawRoundRectComplex(0,0,width,height,5,5,5,5);
		square.graphics.endFill();
		setBackgroundDecorator(new AssetBackground(square as DisplayObject));
		
		//panelIcon.filters = enableUse ? null :filterArrayImage;
		panelIcon.pack();
		panelIcon.paintImmediately();
		this.pack();
		this.paintImmediately();
	}
}